 <!--
* description: 呆滞件销售价格设定
* author: chenjingwen
* createdDate: 2021-3-5
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :callbackObj="callbackObj"
      :dynamic-is-show-select="true"
      :dynamic-is-show-more-btn="true"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import { orgApis } from "@/api/paSparePartsManagement";
import { exportExcel } from '@/utils/getTimeString.js'
import Vue from "vue";

export default {
  name: "salespricesettingofdeadparts",

  components: {
    OneTableTemplate,
    // Edit: () => import("./edit"),
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      // 网格查询API配置对象
      apiConfig: orgApis.unSharQueryData,
      editRowData: {},
      selectData: {},
      editPopupsVisible: false,
      selectiondata: [],

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true,
        },
         {
          compKey: "btnKey2",
          type: "primary",
          size: "small",
          name: "save",
          clickEvent: () => this.save(),
          text: this.$t("sys.button.save"), // 保存
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey3",
          type: "primary",
          size: "small",
          name: "export",
          clickEvent: () => this.export(),
          text: this.$t("sys.button.export"), // 导出
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey4",
          type: "",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right", // 重置
        },
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
              {
                compKey: "key1",
                labelName: "仓库名称:",
                codeField: "warehouseId",
                lookuptype: "VE0185",
                component: () => import("@/components/org/commonSelect"),
                customObj: {
                  api: orgApis.partunDown,
                  defOptionFields:['warehouseId','warehouseName']
                },
                type: "dropdownList",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "key2",
                labelName: "维修类型:",
                codeField: "partRepairType",
                lookuptype: "VE0185",
                component: () => import("@/components/org/commonSelect"),
                customObj: {
                  api: orgApis.siteDefinitionSparePartsQueryselect,
                  // defOptionFields:['warehouseId','warehouseName']
                },
                type: "dropdownList",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "key3",
                labelName: "备件编码:",
                codeField: "partNo",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "key4",
                labelName: "备件名称:",
                codeField: "partName",
                lookuptype: "VE0185",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "key5",
                labelName: "价格启用日期:",
                codeField: 'startDate,endDate',
                component: () => import("@/components/org/datePicker/andtDatePicker"),
                type:'YYYY-MM-DD',
                format: 'yyyy-MM-dd',
                dateOptionsType: '0',
                isMul: false,
                isMust: false,
              },
             {
                compKey: "key6",
                labelName: "审核状态:",
                codeField: "auditStatus",
                component: () => import("@/components/wms/dropdownList/dropdownList"),
                type: "dropdownList",
                options: [
                  {
                    label: "未提交",
                    value: "0"
                  },
                  {
                    label: "已提交",
                    value: "1"
                  },
                  {
                    label: "已生效",
                    value: "2"
                  },
                  {
                    label: "已驳回",
                    value: "3"
                  }
                ],
                isMul: false,
                isMust: false,
              },
              {
                compKey: "key7",
                labelName: "积压天数:",
                codeField: "backlogDays",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false,
              },

            
            ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "subsidyId",
                label: "主键ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "updateControlId",
                label: "并发控制ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "warehouseName",
                label: "仓库名称",
              },
              {
                prop: "partNo",
                label: "备件编号",
              },
              {
                prop: "partName",
                label: "备件名称",
              },
              {
                prop: "partRepairTypeName",
                label: "维修类型",
              },
              {
                prop: "storeQty",
                label: "账面库存",
              },
              {
                prop: "availableInventory",
                label: "可用库存",
              },
              {
                prop: "pointPriceTax",
                label: "成本价",
              },
              {
                prop: "userPrice",
                label: "用户价",
              },

              {
                prop: "sharePrice",
                label: "当前销售价",
              },
              {
                prop: "futureSalesPrice",
                label: "未来销售价+",
                isComponent: true,
                comps: [
                  {
                    compKey: "futureSalesPrice",
                    codeField: "futureSalesPrice",
                    component: () => import("@/components/org/commonInput"),
                  },
                ],
              },
              {
                prop: "lastIndate",
                label: "最新有效入库日期",
              },
              {
                prop: "lastOutdate",
                label: "最新有效出库日期",
              },
              {
                prop: "activeMark",
                label: "审核意见",
              },
               {
                prop: "auditStatus",
                label: "审核状态",
              },
            ],

      // 表单数据
      formField: this.$utils.getFormField(
        this,
        {
          warehouseId: "",
          partRepairType: "",
          partNo: "",
          partName: "",
          startDate: "",
          endDate: "",
          auditStatus: "",
          backlogDays: ""
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
      callbackObj: {
        // 手动勾选网格时，拿到勾选网格的数据
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection;
        },
        onCheckSelectAll: (selection) => {
          this.selectiondata = selection;
        }
      },
    };
  },

  mounted() {
    // 列表查询
    this.queryTable(1);

    // this.$refs.multipleTable.list = [
    //   {
    //     index: 1,
    //   },
    // ];
  },

  methods: {
    export(){
      exportExcel(this.formField, orgApis.unSharExportDetails.APIUrl, orgApis.unSharExportDetails.ServiceCode, '呆滞件销售价格设定')
    },
    save() {
      let that = this;
      let infoQue = [];
      infoQue = this.selectiondata
      if(infoQue.length == 0) {
        this.$message({
          message: "请勾选数据后进行保存",
          type: "success",
          duration: 2000,
        })
      } else {
        let queryObj = {
        apiConfig: orgApis.unSharSave,
        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: infoQue,
        },
      };
      //转换了中台请求格式数据
      var paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      that.$requestAPI(paramD).then((response) => {
        if (response.result === "0") {
          that.$message({
            message: response.msg,
            type: "success",
            duration: 2000,
          })
        }
        var getResult = response;
        if (getResult.result === "1") {
          that.$message({
            message: "保存成功",
            type: "success",
            duration: 2000,
          })
          that.queryTable(1);
        } else {
          that.$message({
            message: getResult.msg,
            type: "warning",
            duration: 2000,
          });
        }
      })
      }
    },
  },
};
</script>
